﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UDP发送端
{
    public partial class PortSelectForm : Form
    {
        public PortSelectForm()
        {
            InitializeComponent();

            // 初始化显示的数据
            initFormData();
        }

        private void PortSelectForm_Load(object sender, EventArgs e)
        {

        }

        // 初始化显示的数据
        private void initFormData()
        {
            this.numericUpDown1.Value = Properties.Settings.Default.clientPort;
            this.numericUpDown2.Value = Properties.Settings.Default.serverPort;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("确定保存设置？确定后将自动重启程序生效。", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dialogResult == DialogResult.OK)
            {
                Properties.Settings.Default.clientPort = (int)this.numericUpDown1.Value;
                Properties.Settings.Default.serverPort = (int)this.numericUpDown2.Value;
                Properties.Settings.Default.Save();

                // 重启程序生效
                Application.Restart();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("确定恢复默认？确定后将自动重启程序生效。", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (dialogResult == DialogResult.OK)
            {
                Properties.Settings.Default.clientPort = 0;
                Properties.Settings.Default.serverPort = 4705;
                Properties.Settings.Default.Save();

                // 重启程序生效
                Application.Restart();
            }
        }
    }
}
